//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================


//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - S+S Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeUI;
using LitwareHR.Infrastructure.Interface;
using Microsoft.Practices.CompositeUI.EventBroker;
using LitwareHR.PublicApp.WinUX.Constants;

using LitwareHR.Infrastructure.Interface.Constants;

namespace LitwareHR.PublicApp.WinUX
{
    public partial class DefaultViewPresenter : Presenter<IDefaultView>
    {
        /// <summary>
        /// This method is a placeholder that will be called by the view when it has been loaded.
        /// </summary>
        public override void OnViewReady()
        {
            base.OnViewReady();
            View.LoadResources();
        }

        /// <summary>
        /// Close the view
        /// </summary>
        public void OnCloseView()
        {
            base.CloseView();
            WorkItem.SmartParts.Remove(View);
            if (View is IDisposable)
                ((IDisposable)View).Dispose();
        }

        [EventSubscription(EventTopicNames.MetaModelUpdating, ThreadOption.UserInterface)]
        public void OnMetaModelUpdating(object sender, EventArgs eventArgs)
        {
            // Start
            View.StartSyncAnimation();
        }

        [EventSubscription(EventTopicNames.MetaModelUpdated, ThreadOption.UserInterface)]
        public void OnMetaModelUpdated(object sender, EventArgs eventArgs)
        {
            // End
            View.NotifySchemaChanges();
            View.EndSyncAnimation();
        }

        [EventSubscription(EventTopicNames.DataSynchronizing, ThreadOption.UserInterface)]
        public void OnDataSynchronizing(object sender, EventArgs eventArgs)
        {
            // Start
            View.StartSyncAnimation();
        }

        [EventSubscription(EventTopicNames.DataSynchronized, ThreadOption.UserInterface)]
        public void OnDataSynchronized(object sender, EventArgs eventArgs)
        {
            // End
            View.EndSyncAnimation();
        }
    }
}

